<template>
  <el-dialog title="提示" :visible.sync="show" width="600px">
    <div>
      <el-form ref="ruleForm" :rules="rules" label-position="top" label-width="80px" :model="ruleForm">
        <el-form-item label="课程类型" prop="category_id" required>
          <el-select v-model="ruleForm.category_id">
            <el-option v-for="item in categoryList" :key="item.id" :value="item.id" :label="item.name" />
          </el-select>
        </el-form-item>
        <el-form-item label="课程名称" prop="course_name" required>
          <el-input v-model="ruleForm.course_name" />
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="show = false">取 消</el-button>
      <el-button type="primary" @click="onAdd">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { mapGetters } from 'vuex'
import { http } from '@/api'

export default {
  name: 'PageAdd',
  data() {
    return {
      show: false,
      ruleForm: {},
      rules: {},
      currentItem: {},
      teacherList: []
    }
  },
  computed: {
    ...mapGetters(['categoryList'])
  },
  created() {
    http.teacher.list().then(res => {
      this.teacherList = res
    })
  },
  methods: {
    open(item) {
      this.ruleForm = { ...item || {}}
      this.show = true
    },
    onAdd() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          this.$emit('save', this.ruleForm)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
